﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.GoodsDelivery;
using MINERP.MODEL.GoodsDelivery;

namespace ERPGoodsDelivery.Return
{
    public partial class FrmReturnFind : Form
    {
        //属性
        private static FrmReturnFind _instance;
        public static FrmReturnFind GetInstance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmReturnFind();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }
        //参数
        private GoodsReturnBLL bll = new GoodsReturnBLL();
        private DeliverFindBLL dbll = new DeliverFindBLL();
        public FrmReturnFind()
        {
            InitializeComponent();
        }

        private void FrmReturnFind_Load(object sender, EventArgs e)
        {
            BindShop();
            SetDefaultTime();
        }
        //查询
        private void btnFind_Click(object sender, EventArgs e)
        {
            try
            {
                Find();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "确认", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        //----------------公共方法--------------------
        #region 绑定商户
        /// <summary>
        /// 绑定商户
        /// </summary>
        private void BindShop()
        {
            try
            {
                List<ShopNormal> shops = dbll.GetShopList();
                //排序
                shops = shops.OrderBy(p => p.ShopName).ToList();
                cbShopList.DisplayMember = "ShopName";
                cbShopList.ValueMember = "ShopId";
                cbShopList.DataSource = shops;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        public void SetDefaultTime()
        {
            dtStart.Value = DateTime.Now.AddDays(-10);
            dtEnd.Value = DateTime.Now.AddDays(1);
        }

        #region 查询
        /// <summary>
        /// 查询
        /// </summary>
        public void Find()
        {
            try
            {
                int shopId = Convert.ToInt32(cbShopList.SelectedValue);
                string ctmName = txtCtmName.Text.Trim();
                DateTime start = dtStart.Value;
                DateTime end = dtEnd.Value;
                List<GoodsReturnBLL.ReturnOrderInfo> infos = bll.FindReturnOrderInfo(shopId, ctmName, start, end);
                gcReturnOrderInfo.DataSource = infos;
                gcReturnOrderInfo.RefreshDataSource();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
